---
title: "Is a Picture Worth 280 Characters?"
subtitle: "Follow-On Experiments (Appendix C)" 
author: "Benjamin Norwood Harris"
output: pdf_document
---

```{r}


library(stargazer)
library(lmtest)
library(ggplot2)
library(TOSTER)

#set WD and read in data.  

setwd("/Users/harri/Dropbox (MIT)/Is a Picture Worth 280 Characters (Updated)/JEPS, Submission Folder, July 2023/JEPS 2nd R+R/Replication Materials/")
DF3 <-read.csv("Data, Follow-On Experiments, June 2023.csv", fileEncoding = "UTF-8-BOM")
```



#Demographic Table Stats 


```{r}
### demographics 

table(DF3$Q.Female)

length(na.omit(DF3$Q.Female[DF3$Q.Female==0]))/length(DF3$Q.Female)
sum(na.omit(DF3$Q.Female))/length(DF3$Q.Female)

sum(is.na(DF3$Q.Female))/length(DF3$Q.Female)

```


```{r}
sum(na.omit(DF3$Q.White))/length((DF3$Q.White))
sum(na.omit(DF3$Q.Black))/length((DF3$Q.Black))
```


```{r}
sum(na.omit(DF3$Q.AIorAN))/length((DF3$Q.AIorAN))
sum(na.omit(DF3$Q.Asian))/length((DF3$Q.Asian))
```


```{r}
sum(na.omit(DF3$Q.NHorPI))/length((DF3$Q.NHorPI))
sum(na.omit(DF3$Q.Hispanic))/length((DF3$Q.Hispanic))
```


```{r}
sum(na.omit(DF3$Q.Mixed))/length((DF3$Q.Mixed))
sum(na.omit(DF3$Q.Other))/length((DF3$Q.Other))
```


```{r}
sum(na.omit(DF3$Q.Other_Mixed))/length((DF3$Q.Other_Mixed))
sum(is.na(DF3$Q.Race))/length(DF3$Q.Race)



```


```{r}
summary(DF3$Q.Age)
```


```{r}


table(DF3$Q.Education)

sum((na.omit(DF3$Q.HighSchool)))/length((DF3$Q.HighSchool))
sum((na.omit(DF3$Q.Bach)))/length((DF3$Q.Bach))

sum(is.na(DF3$Q.Education))/length(DF3$Q.Education)

```


```{r}
table(DF3$Q.Income)


length(na.omit(DF3$Q.Income[DF3$Q.Income==1]))/length(DF3$Q.Income)
length(na.omit(DF3$Q.Income[DF3$Q.Income==2]))/length(DF3$Q.Income)
```


```{r}
length(na.omit(DF3$Q.Income[DF3$Q.Income==3]))/length(DF3$Q.Income)
length(na.omit(DF3$Q.Income[DF3$Q.Income==4]))/length(DF3$Q.Income)
```


```{r}
length(na.omit(DF3$Q.Income[DF3$Q.Income==5]))/length(DF3$Q.Income)
length(na.omit(DF3$Q.Income[DF3$Q.Income==6]))/length(DF3$Q.Income)
```


```{r}
length(na.omit(DF3$Q.Income[DF3$Q.Income==7]))/length(DF3$Q.Income)
length(na.omit(DF3$Q.Income[DF3$Q.Income==8]))/length(DF3$Q.Income)



sum(is.na(DF3$Q.Income))/length(DF3$Q.Income)

```


```{r}


table(DF3$Q.Political_ID)

sum(na.omit(DF3$Q.Liberal))/length((DF3$Q.Liberal))
sum(na.omit(DF3$Q.Moderate))/length((DF3$Q.Moderate))
sum(na.omit(DF3$Q.Conservative))/length((DF3$Q.Conservative))


sum(is.na(DF3$Q.Political_ID))/length(DF3$Q.Political_ID)

```


```{r}

table(DF3$Q.Veteran)
length(na.omit(DF3$Q.Veteran[DF3$Q.Veteran==0]))/length(DF3$Q.Veteran)
length(na.omit(DF3$Q.Veteran[DF3$Q.Veteran==1]))/length(DF3$Q.Veteran)

sum(is.na(DF3$Q.Veteran))/length(DF3$Q.Veteran)


```



```{r}

#Twitter_Use 

table(DF3$Q.Twitter_Use)



length(na.omit(DF3$Q.Twitter_Use[DF3$Q.Twitter_Use==1]))/length(DF3$Q.Twitter_Use)
length(na.omit(DF3$Q.Twitter_Use[DF3$Q.Twitter_Use==2]))/length(DF3$Q.Twitter_Use)
length(na.omit(DF3$Q.Twitter_Use[DF3$Q.Twitter_Use==3]))/length(DF3$Q.Twitter_Use)
length(na.omit(DF3$Q.Twitter_Use[DF3$Q.Twitter_Use==4]))/length(DF3$Q.Twitter_Use)
length(na.omit(DF3$Q.Twitter_Use[DF3$Q.Twitter_Use==5]))/length(DF3$Q.Twitter_Use)
sum(is.na(DF3$Q.Twitter_Use))/length(DF3$Q.Twitter_Use)

```




# Tweet Analysis 

## Substantive Questions


```{r}

##DV: POTUS_Support, IV: Tweet binary  

## Model 1: No Demographics 

T.Potus_Form_1 <- POTUS_Support ~ Tweet   

## Model 5: Factor Demographics 

T.Potus_Form_5 <- 
  POTUS_Support ~ Tweet + Q.Female +
  relevel(as.factor(Q.Race), ref = 1) + #makes white the reference cat
  Q.Age + Q.HighSchool + Q.Bach + 
  factor(Q.Income, ordered = TRUE, levels = c(1, 2, 3, 4, 5, 6, 7, 8)) +  #treats income as an ordered factor
  factor(Q.Political_ID, ordered = TRUE, levels = c(1, 2, 3, 4, 5)) + #treats party as an ordered factor 
  Q.Veteran + factor(Q.Twitter_Use, ordered = TRUE, levels = c(1, 2, 3, 4, 5))
  
## Model 7: Slightly simplified for the Appendix 

T.Potus_Form_7 <- POTUS_Support ~ Tweet + Q.Female + 
  relevel(as.factor(Q.Race), ref = 1) + #makes white the reference cat
  Q.Age + Q.Bach + Q.Income +  #treats income as a continuous variable, removes high school dummy 
  Q.Conservative + Q.Liberal + #uses party binaries 
  Q.Veteran + Q.Twitter_Some

#regression 

T.Potus_1 <- lm(T.Potus_Form_1, 
             data = DF3, 
             na.action=na.omit)

T.Potus_5 <- lm(T.Potus_Form_5, 
             data = DF3, 
             na.action=na.omit)

T.Potus_7 <- lm(T.Potus_Form_7, 
             data = DF3, 
             na.action=na.omit)


stargazer(T.Potus_1, T.Potus_5, T.Potus_7, title = "Twitter, Support for President", no.space = TRUE)

```
```{r}
summary(T.Potus_5)
```







# ICA Analysis 

## Substantive Questions


```{r}

##DV: Authenticity, IV: ICA binary  

## Model 1: No Demographics 

I.Auth_Form_1 <- Authenticity ~ ICA   

## Model 5: Factor Demographics 

I.Auth_Form_5 <- 
  Authenticity ~ ICA + Q.Female +
  relevel(as.factor(Q.Race), ref = 1) + #makes white the reference cat
  Q.Age + Q.HighSchool + Q.Bach + 
  factor(Q.Income, ordered = TRUE, levels = c(1, 2, 3, 4, 5, 6, 7, 8)) +  #treats income as an ordered factor
  factor(Q.Political_ID, ordered = TRUE, levels = c(1, 2, 3, 4, 5)) + #treats party as an ordered factor 
  Q.Veteran + factor(Q.Twitter_Use, ordered = TRUE, levels = c(1, 2, 3, 4, 5))
  
## Model 7: Slightly simplified for the Appendix 

I.Auth_Form_7 <- Authenticity ~ ICA + Q.Female + 
  relevel(as.factor(Q.Race), ref = 1) + #makes white the reference cat
  Q.Age + Q.Bach + Q.Income +  #treats income as a continuous variable, removes high school dummy 
  Q.Conservative + Q.Liberal + #uses party binaries 
  Q.Veteran + Q.Twitter_Some

#regression 

I.Auth_1 <- lm(I.Auth_Form_1, 
             data = DF3, 
             na.action=na.omit)

I.Auth_5 <- lm(I.Auth_Form_5, 
             data = DF3, 
             na.action=na.omit)

I.Auth_7 <- lm(I.Auth_Form_7, 
             data = DF3, 
             na.action=na.omit)


stargazer(I.Auth_1, I.Auth_5, I.Auth_7, title = "Leaked ICA, Perceived Authenticity", no.space = TRUE)

```



```{r}

##DV: Supplied_Check_Binary, IV: ICA binary  

## Model 1: No Demographics 

I.Supplied_Form_1 <- Supplied_Check_Binary ~ ICA   

## Model 5: Factor Demographics 

I.Supplied_Form_5 <- 
  Supplied_Check_Binary ~ ICA + Q.Female +
  relevel(as.factor(Q.Race), ref = 1) + #makes white the reference cat
  Q.Age + Q.HighSchool + Q.Bach + 
  factor(Q.Income, ordered = TRUE, levels = c(1, 2, 3, 4, 5, 6, 7, 8)) +  #treats income as an ordered factor
  factor(Q.Political_ID, ordered = TRUE, levels = c(1, 2, 3, 4, 5)) + #treats party as an ordered factor 
  Q.Veteran + factor(Q.Twitter_Use, ordered = TRUE, levels = c(1, 2, 3, 4, 5))
  
## Model 7: Slightly simplified for the Appendix 

I.Supplied_Form_7 <- Supplied_Check_Binary ~ ICA + Q.Female + 
  relevel(as.factor(Q.Race), ref = 1) + #makes white the reference cat
  Q.Age + Q.Bach + Q.Income +  #treats income as a continuous variable, removes high school dummy 
  Q.Conservative + Q.Liberal + #uses party binaries 
  Q.Veteran + Q.Twitter_Some

#regression 

I.Supplied_1 <- lm(I.Supplied_Form_1, 
             data = DF3, 
             na.action=na.omit)

I.Supplied_5 <- lm(I.Supplied_Form_5, 
             data = DF3, 
             na.action=na.omit)

I.Supplied_7 <- lm(I.Supplied_Form_7, 
             data = DF3, 
             na.action=na.omit)


stargazer(I.Supplied_1, I.Supplied_5, I.Supplied_7, title = "Leaked ICA, Supplied Check", no.space = TRUE)

```
```{r}
summary(I.Supplied_5)
```


# Means and SE Estimates 

## Twitter 

### Substantive Questions 


```{r}
##### POTUS_Support

T.Potus_Full_1 <- POTUS_Support ~ 0 + as.factor(Tweet) 


lm_T.Potus_Full_1 <- lm(T.Potus_Full_1, 
                     data = DF3)

summary(lm_T.Potus_Full_1)
length(na.omit(DF3$POTUS_Support[DF3$Tweet==1]))
length(na.omit(DF3$POTUS_Support[DF3$Tweet==0]))
```


### Timing and AC 


## Leaked ICA 

### Substantive Questions 



```{r}
##### Authenticity

I.Auth_Full_1 <- Authenticity ~ 0 + as.factor(ICA) 


lm_I.Auth_Full_1 <- lm(I.Auth_Full_1, 
                     data = DF3)

summary(lm_I.Auth_Full_1)
length(na.omit(DF3$Authenticity[DF3$ICA==1]))
length(na.omit(DF3$Authenticity[DF3$ICA==0]))
```



### Timing and AC 



```{r}
##### Supplied_Check_Binary

I.Supplied_Full_1 <- Supplied_Check_Binary ~ 0 + as.factor(ICA) 


lm_I.Supplied_Full_1 <- lm(I.Supplied_Full_1, 
                     data = DF3)

summary(lm_I.Supplied_Full_1)
length(na.omit(DF3$Supplied_Check_Binary[DF3$ICA==1]))
length(na.omit(DF3$Supplied_Check_Binary[DF3$ICA==0]))
```




# Graphs 

## Twitter 

### Substantive Questions 

```{r}

#put all the names, estimates, SEs, and behavior into one df for graphing 
Results_DF <- as.data.frame(matrix(data = c(
                                   "POTUS Support", coeftest(T.Potus_1)[2, 1:2],"no", 
                                   "POTUS Support", coeftest(T.Potus_5)[2, 1:2], "yes"), 
                                   ncol = 4, byrow = TRUE))

colnames(Results_DF) <- c("dv", "estimate", "se", "controls")

#making into correct operators 
Results_DF$dv <- factor(Results_DF$dv, levels = c("POTUS Support"))
Results_DF$estimate <- as.numeric(Results_DF$estimate)
Results_DF$se <- as.numeric(Results_DF$se)

#adding in CIs 
q <- as.numeric(qnorm(p=.05/2, lower.tail=FALSE))
Results_DF$ci <- Results_DF$se*q


## graph time 
pd <- position_dodge(0.5)

ggplot(Results_DF, aes(x = dv, y = estimate, color = controls))  + 
  geom_point(aes(color=controls, shape=controls), position = pd) +
  geom_errorbar(aes(ymin = estimate - ci, ymax = estimate + ci), width = .2, position = pd) +
  theme_minimal() + xlab("Question") + ylab("ATE") + 
  geom_hline(yintercept = 0, linetype="dotted") +
  theme(axis.text.x = element_text(hjust = 1), text = element_text(size = 14)) + coord_flip()

#   ggtitle("ATE of Tweet Treatment on Substantive DVs") #removed for paper 

```




## Leaked ICA 


### Substantive Questions 


```{r}

#put all the names, estimates, SEs, and behavior into one df for graphing 
Results_DF <- as.data.frame(matrix(data = c(
                                   "Authenticity", coeftest(I.Auth_1)[2, 1:2], "no",
                                   "Authenticity", coeftest(I.Auth_5)[2, 1:2], "yes"), 
                                   ncol = 4, byrow = TRUE))

colnames(Results_DF) <- c("dv", "estimate", "se", "controls")

#making into correct operators 
Results_DF$dv <- factor(Results_DF$dv, levels = c("Authenticity"))
Results_DF$estimate <- as.numeric(Results_DF$estimate)
Results_DF$se <- as.numeric(Results_DF$se)

#adding in CIs 
q <- as.numeric(qnorm(p=.05/2, lower.tail=FALSE))
Results_DF$ci <- Results_DF$se*q


## graph time 
pd <- position_dodge(0.5)

ggplot(Results_DF, aes(x = dv, y = estimate, color = controls))  + 
  geom_point(aes(color=controls, shape=controls), position = pd) +
  geom_errorbar(aes(ymin = estimate - ci, ymax = estimate + ci), width = .2, position = pd) +
  theme_minimal() + xlab("Question") + ylab("ATE") + 
  geom_hline(yintercept = 0, linetype="dotted") +
  theme(axis.text.x = element_text(hjust = 1), text = element_text(size = 14)) + coord_flip()

#   ggtitle("ATE of ICA Treatment on Substantive DVs") #removed for paper 

```

### Timer and AC


```{r}

#put all the names, estimates, SEs, and behavior into one df for graphing 
Results_DF <- as.data.frame(matrix(data = c(
                                   "Supplied Check", coeftest(I.Supplied_1)[2, 1:2], "no",
                                   "Supplied Check", coeftest(I.Supplied_5)[2, 1:2], "yes"
                                   ), 
                                   ncol = 4, byrow = TRUE))

colnames(Results_DF) <- c("dv", "estimate", "se", "controls")

#making into correct operators 
Results_DF$dv <- factor(Results_DF$dv, levels = c("Supplied Check"))
Results_DF$estimate <- as.numeric(Results_DF$estimate)
Results_DF$se <- as.numeric(Results_DF$se)

#adding in CIs 
q <- as.numeric(qnorm(p=.05/2, lower.tail=FALSE))
Results_DF$ci <- Results_DF$se*q


## graph time 
pd <- position_dodge(0.5)

ggplot(Results_DF, aes(x = dv, y = estimate, color = controls))  + 
  geom_point(aes(color=controls, shape=controls), position = pd) +
  geom_errorbar(aes(ymin = estimate - ci, ymax = estimate + ci), width = .2, position = pd) +
  theme_minimal() + xlab("Question") + ylab("ATE") + 
  geom_hline(yintercept = 0, linetype="dotted") +
  theme(axis.text.x = element_text(hjust = 1), text = element_text(size = 14)) + coord_flip()

#   ggtitle("ATE of ICA Treatment on Attention Checks") #removed for paper 

```



```{r}

```

